package com.dmp.pushlogs.bolt;

import com.dmp.common.date.DateUtils;
import com.dmp.storm.bolt.BaseMapBolt;

import java.util.Date;
import java.util.Map;

/**
 * @ClassName RedirectCustomBolt
 * @Description 本地化字段处理
 *
 * @author sunzy
 * @date 2016年4月14日 下午4:37:42
 * @version 1.0
 * 
 */
public class FailCustomBolt extends BaseMapBolt {
	/**
	 * 
	 */
	private static final long serialVersionUID = -3372732981391364586L;

	@Override
	public Map<String, Object> process(Map<String, Object> map) {
		Map<String, Object> record = map;
		try {

			// 日期转换 dd/MMM/yyyy:HH:mm:ss Z -> yyyyMMddHHmmss
			String logTime = (String) map.get("fe_time");
			long time = Long.parseLong(logTime);
			Date logDate = new Date(time);
			logTime = DateUtils.formatDate(logDate, "yyyyMMddHHmmss");
			record.put("fe_time", logTime);

			// 日期转换 dd/MMM/yyyy:HH:mm:ss Z -> yyyyMMddHHmmss
			String failLogTime = (String) map.get("log_time");
			time = Long.parseLong(failLogTime);
			Date logDateAdpush = new Date(time);
			failLogTime = DateUtils.formatDate(logDateAdpush, "yyyyMMddHHmmss");
			record.put("log_time", failLogTime);

			// 其它时间
			record.put("hour", DateUtils.formatDate(logDate, "yyyyMMddHH"));
			record.put("hour_h", DateUtils.formatDate(logDate, "HH"));
			record.put("day", DateUtils.formatDate(logDate, "yyyyMMdd"));
			record.put("day_d", DateUtils.formatDate(logDate, "dd"));
			record.put("month", DateUtils.formatDate(logDate, "yyyyMM"));
			record.put("month_m", DateUtils.formatDate(logDate, "MM"));
			
			//日志时间
			record.put("log_date", DateUtils.formatDate(logDateAdpush, "yyyy/MM/dd HH:mm:ss"));
			
			//对fail_type进行初始化
			String failType = (String) map.get("fail_type");
			if(failType==null||failType.equals("")){
				record.put("fail_type", "0");
			}

		} catch (Exception e) {
			System.err.println(map);
			e.printStackTrace();

			return null;
		}
		return record;
	}
}
